package com.ljt.disruptordemo;

import com.lmax.disruptor.RingBuffer;
import com.lmax.disruptor.SleepingWaitStrategy;
import com.lmax.disruptor.dsl.Disruptor;
import com.lmax.disruptor.dsl.ProducerType;

import java.util.concurrent.Executors;

/**
 * 这个类值不用spring框架的时候，使用方式
 */
public class EventProcessingSystem {
    public static void main(String[] args) {
        Disruptor<MyEvent> disruptor = new Disruptor<>(
                new MyEventFactory(),
                1024,
                Executors.defaultThreadFactory(),
                ProducerType.SINGLE,
                new SleepingWaitStrategy()
        );
        
        disruptor.handleEventsWith(new MyEventHandler());
        disruptor.start();
        
        RingBuffer<MyEvent> ringBuffer = disruptor.getRingBuffer();
        ringBuffer.publishEvent((myEvent, sequence) -> {
            myEvent.setData("Sample Event");
        });

        disruptor.shutdown();
    }
}